package androidServlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.TimeZone;

import javax.servlet.ServletException;
import javax.servlet.http.*;

import com.tecnick.htmlutils.htmlentities.HTMLEntities;

import sessionMenegment.SessionMgr;

import controller.Controller;
import dataBase.Order;

@SuppressWarnings("serial")
public class AllBusinessAndroid extends HttpServlet {

	public AllBusinessAndroid() {
	}

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
	throws IOException {

		ArrayList<String> bizNames = Controller.getInstance().allBizNameArray();

		PrintWriter out = resp.getWriter();
		boolean first = true;
		out.println("{\"businesses\": [");

		for (String name: bizNames)
		{

			if (first)
				first = false;
			else
				out.println(",");


			out.println("  {");
			out.print("    \"name\": ");
			out.print("\""+name+"\"");
			out.println(",");
			out.print("    \"keyID\": ");
			out.print("\""+Controller.getInstance().bizNameToKeyID(name)+"\"");
			out.println("  }");

		}

		out.println("] }");
		out.flush();


	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
	throws ServletException, IOException {

	}

}
